import { getBaseUrl } from '@/services/urlconst';
import { requestFunComponFiex } from '@/utils';
import { useMemo } from 'react';
import { useRequest } from 'umi';

const baseUrl = getBaseUrl();

/**
 * 查看当前流程进度
 * @controller 业务controller
 * @returns
 */
const getImageByProcInstIDService = (callBack: (res: any) => void) => {
  const getImageByProcInstID = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/contractController/getImageByProcInstID/${params?.procInstID}`;
      return requestFunComponFiex('GET', personUrl, {});
    },
    {
      manual: true,
      onSuccess: callBack,
    },
  );

  const data = useMemo(() => {
    return getImageByProcInstID?.data;
  }, [getImageByProcInstID?.data]);

  return {
    getImageByProcInstIDRun: getImageByProcInstID?.run,
    getImageByProcInstIDLoading: getImageByProcInstID?.loading,
    getImageByProcInstIDData: data,
  };
};

/** OA页面已读已办消息推送 */
const setOAMessageSev = (cb: (res: Record<string, any>) => void) => {
  const request = useRequest(
    (payload) => {
      let bodyParams = {
        ...payload,
      };
      let reqUrl = `${baseUrl}/taskPushController/syncPushTask`;
      return requestFunComponFiex('PUT', reqUrl, bodyParams);
    },
    {
      manual: true,
      onSuccess: cb,
    },
  );

  return {
    setOAMessageRun: request?.run,
    setOAMessageLoaidng: request?.loading,
  };
};

export { getImageByProcInstIDService, setOAMessageSev };
